package com.group6.exam.manager.service;

import java.util.Map;

import com.group6.exam.common.entity.PageModel;
import com.group6.exam.manager.dao.GradeDaoImpl;
import com.group6.exam.manager.dao.IGradeDao;

public class GradeServiceImpl implements IGradeService {

	private IGradeDao gradeDao = new GradeDaoImpl();

	// 删除
	@Override
	public int deleteGradeById(String gradeId) {

		return gradeDao.deleteGradeById(gradeId);
	}

	// 修改前查询
	@Override
	public Map<String, Object> preUpdateGradeById(String gradeId) {

		return gradeDao.preUpdateGradeById(gradeId);
	}

	// 修改
	@Override
	public int updateGrade(String gradeName, String gradeId) {
		return gradeDao.update(gradeName, gradeId);
	}

	// 增加
	@Override
	public int add(String gradeName) {
		return gradeDao.update(gradeName);
	}

	// 分页的业务方法
	@Override
	public PageModel getPagingByPageModel(PageModel pageModel) {
		// 构建page对象所需参数
		int totalRecords = gradeDao.getTotalRecords();

		int pageSize = pageModel.getPageSize();
		PageModel page = new PageModel(totalRecords, pageSize);
		// 设置当前页
		page.setCurrentPage(pageModel.getCurrentPage());

		// 设置每页显示的集合对象
		page.setList(gradeDao.getPagingByPageModel(pageModel));

		return page;
	}

}
